package mule.presenter;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.stage.Stage;
import mule.model.GameModel;
import mule.view.NewOrLoadView;

/**
 *
 * @author stephen
 */
public final class NewOrLoadPresenter implements Presenter
{
    private final GameModel model;
    private final NewOrLoadView view;
    private final Stage stage;

    public NewOrLoadPresenter( Stage stage )
    {
        this.stage = stage;
        this.model = GameModel.getInstance();
        this.view = new NewOrLoadView();
    }

    @Override
    public void present()
    {
        stage.setScene( view.getScreen() );
        addListeners();
        stage.show();
    }

    @Override
    public void addListeners() 
    {
        view.addNewGameListener( new EventHandler<ActionEvent>() 
        {
            @Override
            public void handle( ActionEvent event ) 
            {
                NewGameOptionPresenter newGameOptionPresenter = new NewGameOptionPresenter( stage );
                newGameOptionPresenter.present();
            } 
        } );

        view.addLoadGameListener( new EventHandler<ActionEvent>() 
        {
            @Override
            public void handle( ActionEvent event ) 
            {
                LoadGamePresenter loadGamePresenter = new LoadGamePresenter( stage );
                loadGamePresenter.present();
            } 
        } );
    }
}
